package com.ikun.admin.modules.gen.controller;


import com.ikun.admin.common.annotation.OperationAnno;
import com.ikun.admin.modules.gen.entity.FieldType;
import com.ikun.admin.modules.gen.entity.Table;
import com.ikun.admin.modules.gen.entity.TableEntity;
import com.ikun.admin.modules.gen.iservice.ITableService;
import com.ikun.admin.modules.gen.vo.*;
import com.ikun.common.result.Result;
import com.ikun.common.search.PageData;
import com.ikun.common.search.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 建表数据  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2024-04-03
 */
@RestController
@RequestMapping("/develop/table")
@Api(tags = "数据表接口")
public class TableController {

    @Autowired
    private ITableService iTableService;

    @PostMapping("/table/addOrUpdate/API_001")
    @ApiOperation("新增或修改接口")
    @OperationAnno(type=0,tableEntity = Table.class)
    public Result<String> tableAddOrUpdate(@RequestBody TableAddOrUpdateVo tableAddOrUpdateVo) {
        return iTableService.tableAddOrUpdate(tableAddOrUpdateVo);
    }

    @PostMapping("/table/list/API_002")
    @ApiOperation("分页查询接口")
    public Result<PageResult<TableListResultVo>> tableList(@RequestBody PageData<TableListParamVo> pageData) {
        return iTableService.tableList(pageData);
    }

    @DeleteMapping("/table/delete/API_003/{id}")
    @ApiOperation("根据tableId删除表数据以及字段")
    @OperationAnno(type=0,tableEntity = Table.class)
    public Result<String> tableDelete(@PathVariable Long id) {
        return iTableService.tableDelete(id);
    }

    @GetMapping("/table/dict/API_004")
    @ApiOperation("字典接口")
    public Result<List<TableListResultVo>> tableDict() {
        return iTableService.tableDict();
    }

    @GetMapping("/table/select/API_005/{id}")
    @ApiOperation("查询详情接口")
    public Result<TableDetailVo> tableDetail(@PathVariable Long id) {
        return iTableService.tableDetail(id);
    }

    @GetMapping("/tableEntity/select/API_006/{id}")
    @ApiOperation("查询表字段接口")
    public Result<List<TableFieldDetailVo>> tableFieldDetail(@PathVariable Long id){
        return iTableService.tableFieldDetail(id);
    }
    @PostMapping("tableEntity/addOrUpdate/API_007")
    @ApiOperation("新增或编辑实体表字段")
    @OperationAnno(type=0,tableEntity = TableEntity.class)
    public Result<String> addOrUpdateTableEntity(@RequestBody TableEntityAddOrUpdateVo tableEntityAddOrUpdateVo){
        return iTableService.tableEntityAddOrUpdate(tableEntityAddOrUpdateVo);
    }

}

